﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class ClassesDAO
    {
        public bool Add(Classes classes)
        {
            try
            {
                DBHelper.TransInsert(classes);
                return true;
            }
            catch (Exception ex)
            {
               
                return false;
            }
        }
        public bool DeleteClassByID(int id)
        {
            DBHelper.ExecuteHQL("delete from Classes where id="+id.ToString()+"").ExecuteUpdate();
            return true;
        }
        public IList<Classes> GetClasses(int pageSize, int page)
        {
            return DBHelper.ExecuteHQL("from Classes order by id desc ").SetFirstResult((page-1)*pageSize).SetMaxResults(pageSize).List<Classes>();
        }

        public bool Modify(Classes classes)
        {
            DBHelper.TransUpdate(classes);
            return true;
        }

        public void Delete(int id)
        {
            DBHelper.TransDeleteByID("Classes",id);
        }

        public Classes GetClassByID(int id)
        {
            return (Classes)DBHelper.GetObject(typeof(Classes),id);
        }

        public int GetTotalClass()
        {
            return Convert.ToInt32( DBHelper.ExecuteHQL("select count(id) from Classes ").UniqueResult());
        }
    }
}
